/**
 * Copyright © 2016-2025 The Thingsboard Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.terracloud.server.common.data.log;

import com.terracloud.server.common.data.BaseData;
import com.terracloud.server.common.data.id.DeviceId;
import com.terracloud.server.common.data.id.TenantId;
import com.terracloud.server.common.data.id.TerminalLogId;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 终端日志实体类
 * 用于记录来自设备或终端的日志信息
 */
@Schema
@Data
@EqualsAndHashCode(callSuper = true)
public class TerminalLog extends BaseData<TerminalLogId> {

    @Schema(description = "租户ID")
    private TenantId tenantId;
    
    @Schema(description = "设备ID")
    private DeviceId deviceId;
    
    @Schema(description = "设备名称")
    private String deviceName;
    
    @Schema(description = "日志类型")
    private LogType logType;
    
    @Schema(description = "日志级别")
    private LogLevel logLevel;
    
    @Schema(description = "日志内容摘要")
    private String contentSummary;
    
    @Schema(description = "日志详细内容")
    private String contentDetails;
    
    @Schema(description = "发生时间")
    private Long occurTime;
    
    @Schema(description = "处理状态")
    private LogStatus processStatus;
    
    @Schema(description = "处理人")
    private String processor;
    
    @Schema(description = "SLA状态")
    private String slaStatus;
    
    @Schema(description = "SLA截止时间")
    private Long slaDeadline;
    
    @Schema(description = "持续时间(毫秒)")
    private Long duration;
    
    @Schema(description = "是否紧急告警")
    private Boolean isCritical;
    
    public TerminalLog() {
        super();
    }
    
    public TerminalLog(TerminalLogId id) {
        super(id);
    }
    
    /**
     * 判断是否为紧急告警
     * @return true-是紧急告警，false-不是紧急告警
     */
    public boolean isCriticalAlert() {
        return isCritical != null && isCritical;
    }
    
    /**
     * 判断是否超时(持续24小时以上)
     * @return true-超时，false-未超时
     */
    public boolean isTimeout() {
        if (duration == null) {
            return false;
        }
        // 24小时 = 24 * 60 * 60 * 1000 毫秒
        return duration > 86400000L;
    }
}